package com.situ.onlinebookstore.front.controller.api;

import com.situ.onlinebookstore.common.entity.Category;
import com.situ.onlinebookstore.common.vo.Result;
import com.situ.onlinebookstore.front.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 为了与返回视图的Controller区别
 * 加上了Api，表示这些都是返回JSON格式数据的Web Api 接口
 * RESTful 风格的接口
 * url 统一资源访问符
 * 同一种资源访问路径应该是相同的
 */
@RestController
@RequestMapping("api/category")
@RequiredArgsConstructor
public class CategoryApiController {
    private final CategoryService categoryService;

    //查询分类信息
    @GetMapping("")
    public Result search(Integer page, Integer limit, Category category) {
        if (page == null) {
            return Result.ok(categoryService.get(category));
        } else {
            return Result.ok(categoryService.getForPage(page, limit, category));
        }
    }
}
